<?
    /**
     * Smarty plugin
     * @package Smarty
     * @subpackage plugins
     */


    /**
     * Smarty {load_listings} function plugin
     *
     * Type:     function
     * Name:     load_listings
     * Purpose:  Loads most recent listings from the database
     *   @param array
     *   @param Smarty
     *
     * This smarty plugin can be talked to using the following
     * template parameters:
     *   
     *   * var (string)   -- name of variable where to load the 
     *                       data to
     *                       >> default: listings
     *   * toget (string) -- total number of listing to get from
     *                       the database
     *                       >> default: 5
     *
     * @return string
     */
    function smarty_function_load_article_tags($params, &$smarty)
    {
        global $db; // create a link to the database connection

        //pre-process parameters
        //variable name
        if(empty($params['var'])){
            $var = 'tags';
        }else{
            $var = $params['var'];
        }
                                
        $smarty->assign($var,$db->getAll("SELECT name, url, count(tag_page_map.page_id) AS weight FROM tags 
                                                                 LEFT JOIN tag_page_map ON tags.id = tag_page_map.tag_id
                                                                 LEFT JOIN pagemap pm ON tag_page_map.page_id = pm.id
                                                                 WHERE pm.wf_state = 1
                                                                 GROUP BY tags.id, tags.name, tags.url
                                                                 ORDER BY name"));        
    }
?>
